package com.ruoyi.web.controller.iot;

import cn.hutool.core.map.MapUtil;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.modbus.utils.CacheObjectUtils;
import com.ruoyi.common.modbus.utils.CacheShebeiUtils;
import com.ruoyi.common.modbus.utils.CacheUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

@RestController
@RequestMapping("/iot/test")
public class IotTestController extends BaseController {


    @GetMapping("/cache")
    public AjaxResult cache()
    {

//        return success(CacheUtils.map.toString());
        return success(CacheUtils.printMap());
    }

    @GetMapping("/cacheShebei")
    public AjaxResult cacheShebei()
    {

        return success(CacheShebeiUtils.map.toString());
//        return success(CacheObjectUtils.printMap());
    }

    public static void main(String[] args) {
        // 创建一个HashMap并添加一些键值对
        Map<String, Integer> map = new HashMap<>();
        map.put("A", 1);
        map.put("B", 2);
        map.put("C", 1);
        map.put("D", 3);

        // 要删除的值
        int valueToDelete = 1;

        // 遍历Map并删除符合条件的键值对
        Iterator<Map.Entry<String, Integer>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<String, Integer> entry = iterator.next();
            if (entry.getValue().equals(valueToDelete)) {
                // 删除符合条件的键值对
                iterator.remove();
            }
        }

        // 打印删除后的Map
        System.out.println(map); // 输出: {B=2, D=3}
    }

}
